﻿Imports System.Data.OleDb
Public Class RapDAO
    Public Function Insert(ByVal tmp As RapDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into RAP (MaRap, TenRap, DiaChi, MaNVQL ) values (@MaRap, @TenRap, @DiaChi, @MaNVQL)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@MaRap", tmp.MaRap)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TenRap", tmp.TenRap)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@MaNVQL", tmp.MaNVQL)
        cmd.Parameters.Add(para4)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As RapDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update RAP set TenRap=@TenRap,DiaChi=@DiaChi,MaNVQL=@MaNVQL where MaRap=@MaRap"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@MaRap", tmp.MaRap)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TenRap", tmp.TenRap)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@MaNVQL", tmp.MaNVQL)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
    Public Function Delete(ByVal tmp As RapDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from RAP where MaRap=@MaRap"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaRap", tmp.MaRap)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
End Class
